<template>
<div>
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      prop="id"
      label="编号"
      width="180">
    </el-table-column>
    <el-table-column
      prop="bookname"
      label="图书名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="审核员">
    </el-table-column>
    <el-table-column
      prop="sell"
      label="销售数量">
    </el-table-column>
    <el-table-column
      prop="inferior"
      label="次品数量">
    </el-table-column>
    <el-table-column
      prop="surplus"
      label="剩余数量">
    </el-table-column>
    <el-table-column
      prop="price"
      label="价格">
    </el-table-column>
    <el-table-column
      prop="budget"
      label="采购总价">
    </el-table-column>
    <el-table-column
      prop="realityamount"
      label="实际采购数量">
    </el-table-column>
    <el-table-column
      prop="realityprice"
      label="实际价格">
    </el-table-column>
    <el-table-column
      prop="budget"
      label="实际总价">
    </el-table-column>
    <el-table-column
      prop="date"
      label="时间" :formatter="dateFormat">
    </el-table-column>
    <el-table-column
      prop="amount"
      label="入库数量">
    </el-table-column>
    <el-table-column
      prop="budget"
      label="采购总价">
    </el-table-column>
    <el-table-column label="状态">
      <template slot-scope="scope">
        <span v-if="scope.row.state == 0">未审核</span>
        <span v-if="scope.row.state == 1">审核完成</span>
        <span v-if="scope.row.state == 2">采购成功</span>
        <span v-if="scope.row.state == 3">入库成功</span>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    small
    layout="total,prev, pager, next"
    :page-size="pageSize"
    :total="total" @current-change="page">
  </el-pagination>

</div>
</template>

<script>
export default {
  name: "Inventoryrecords",
  data(){
    return{
      tableData:[],
      total: 0,
      pageSize: 6
    }
  },
  created() {
   this.find()
  },
  methods:{
    find(){
      this.$http.post("backservice/inventory/page?pageNum=0&pageSize=" + this.pageSize).then(response => {
        console.log(response.userList)
        this.tableData = response.userList
        this.total = response.TotalNum
      })
    },
    page(currentPage) {
      this.$http.post('backservice/inventory/page?&pageNum=' + (currentPage - 1) + '&pageSize=' + this.pageSize)
        .then(response => {
          this.tableData = response.userList
        })
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property]
      if (daterc != null) {
        var date = new Date(daterc);
        var year = date.getFullYear();
        /* 在日期格式中，月份是从0开始，11结束，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        // 拼接
        return year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
      }
    }
  }
}
</script>

<style scoped>

</style>
